package org.proteored.miapeapi.xml.ms;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.proteored.miapeapi.interfaces.ms.ActivationDissociation;
import org.proteored.miapeapi.interfaces.ms.Analyser;
import org.proteored.miapeapi.interfaces.ms.Esi;
import org.proteored.miapeapi.interfaces.ms.InstrumentConfiguration;
import org.proteored.miapeapi.interfaces.ms.Maldi;
import org.proteored.miapeapi.interfaces.ms.Other_IonSource;
import org.proteored.miapeapi.xml.ms.autogenerated.MSActivationDissociation;
import org.proteored.miapeapi.xml.ms.autogenerated.MSAnalyzer;
import org.proteored.miapeapi.xml.ms.autogenerated.MSESI;
import org.proteored.miapeapi.xml.ms.autogenerated.MSInstrumentConfiguration;
import org.proteored.miapeapi.xml.ms.autogenerated.MSMALDI;
import org.proteored.miapeapi.xml.ms.autogenerated.MSOtherIonSource;

public class InstrumentConfigurationImpl implements InstrumentConfiguration {
	private final MSInstrumentConfiguration xmlInstrumentConfiguration;

	public InstrumentConfigurationImpl(MSInstrumentConfiguration xmlInstrumentConfiguration) {
		this.xmlInstrumentConfiguration = xmlInstrumentConfiguration;
	}

	@Override
	public String getName() {
		return xmlInstrumentConfiguration.getName();
	}

	@Override
	public List<Maldi> getMaldis() {
		List<Maldi> listOfMaldi = new ArrayList<Maldi>();

		List<MSMALDI> maldiList = xmlInstrumentConfiguration.getMSMALDI();
		if (maldiList != null) {
			for (MSMALDI MaldiItem : maldiList) {
				listOfMaldi.add(new MaldiImpl(MaldiItem));
			}
			return listOfMaldi;
		}
		return null;
	}

	@Override
	public List<Esi> getEsis() {
		List<Esi> setOfEsi = new ArrayList<Esi>();

		List<MSESI> esiList = xmlInstrumentConfiguration.getMSESI();
		if (esiList != null) {
			for (MSESI EsiItem : esiList) {
				setOfEsi.add(new EsiImpl(EsiItem));
			}
			return setOfEsi;
		}
		return null;
	}

	@Override
	public List<Other_IonSource> getOther_IonSources() {
		List<Other_IonSource> listOfOther_IonSource = new ArrayList<Other_IonSource>();
		List<MSOtherIonSource> other_IonSourceList = xmlInstrumentConfiguration
				.getMSOtherIonSource();
		if (other_IonSourceList != null) {
			for (MSOtherIonSource msOtherIonSource : other_IonSourceList) {
				listOfOther_IonSource.add(new OtherIonSourceImpl(msOtherIonSource));
			}
			return listOfOther_IonSource;
		}
		return null;
	}

	@Override
	public Set<ActivationDissociation> getActivationDissociations() {
		Set<ActivationDissociation> setOfCollisionCells = new HashSet<ActivationDissociation>();

		/* Get MSCollisionCell list */
		List<MSActivationDissociation> collisionCellList = xmlInstrumentConfiguration
				.getMSActivationDissociation();
		if (collisionCellList != null) {
			for (MSActivationDissociation collisionCellItem : collisionCellList) {
				setOfCollisionCells.add(new ActivationDissociationImpl(collisionCellItem));
			}
			return setOfCollisionCells;
		}
		return null;
	}

	// @Override
	// public Set<IonOptic> getIonOptics() {
	// Set<IonOptic> setOfIonOptics = new HashSet<IonOptic>();
	// List<MSIonOptic> ionOpticsXML =
	// xmlInstrumentConfiguration.getMSIonOptic();
	// if (ionOpticsXML != null) {
	// for (MSIonOptic ionOpticXML : ionOpticsXML) {
	// setOfIonOptics.add(new IonOpticImpl(ionOpticXML));
	// }
	// return setOfIonOptics;
	// }
	// return null;
	// }

	@Override
	public List<Analyser> getAnalyzers() {
		List<Analyser> setOfAnalyzers = new ArrayList<Analyser>();

		List<MSAnalyzer> analyzerList = xmlInstrumentConfiguration.getMSAnalyzer();
		if (analyzerList != null) {
			for (MSAnalyzer analyzerItem : analyzerList) {
				setOfAnalyzers.add(new AnalyzerImpl(analyzerItem));
			}
			return setOfAnalyzers;
		}
		return null;
	}

}
